import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SettingsService {
  static const String _primaryColorKey = 'primary_color';
  static const String _fontSizeScaleFactorKey = 'font_size_scale_factor';
  static const _enableAllNotificationsKey = 'enable_all_notifications';
  static const _taskRemindersKey = 'task_reminders';
  static const _reminderTimeKey = 'reminder_time';

  Future<void> saveThemeColor(Color color) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setInt(_primaryColorKey, color.value);
  }

  Future<Color> loadThemeColor() async {
    final prefs = await SharedPreferences.getInstance();
    final colorValue = prefs.getInt(_primaryColorKey);
    return colorValue != null ? Color(colorValue) : const Color(0xFF6366F1); // Default color
  }

  Future<void> saveFontSizeScaleFactor(double scaleFactor) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setDouble(_fontSizeScaleFactorKey, scaleFactor);
  }

  Future<double> loadFontSizeScaleFactor() async {
    final prefs = await SharedPreferences.getInstance();
    return prefs.getDouble(_fontSizeScaleFactorKey) ?? 1.0; // Default scale factor
  }

  Future<void> saveNotificationSettings({
    required bool enableAll,
    required bool taskReminders,
    required String reminderTime,
  }) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setBool(_enableAllNotificationsKey, enableAll);
    await prefs.setBool(_taskRemindersKey, taskReminders);
    await prefs.setString(_reminderTimeKey, reminderTime);
  }

  Future<Map<String, dynamic>> loadNotificationSettings() async {
    final prefs = await SharedPreferences.getInstance();
    return {
      'enableAll': prefs.getBool(_enableAllNotificationsKey) ?? true,
      'taskReminders': prefs.getBool(_taskRemindersKey) ?? true,
      'reminderTime': prefs.getString(_reminderTimeKey) ?? '15 分钟前',
    };
  }
} 